package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.ParkingLotDao;
import cn.topevery.garden.entity.po.ParkingLot;
import cn.topevery.garden.entity.query.ParkingLotQuery;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author code-generate
 * @date 2021-08-06
 */
@Repository
public class ParkingLotDaoImpl extends BaseDaoImpl<ParkingLot> implements ParkingLotDao {
    @Override
    public <P extends DbCsp> List<ParkingLot> getSearch(P para) {
        return null;
    }


    @Override
    public DataPager<ParkingLot> listPage(ParkingLotQuery query) {
        String table = "t_parking_lot tpl";

        String columns = "tpl.c_id,tpl.c_name,tpl.c_park_name,tpl.c_extent_name,tpl.c_status";
        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tpl.c_id desc");
        sqlQueryMate
                .where(true, "tpl.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotBlank(query.getName()), "tpl.c_name", ScriptConditionEnum.Like, query.getName())
                .where(StringUtils.isNotBlank(query.getParkName()), "tpl.c_park_name", ScriptConditionEnum.Like, query.getParkName())
                .where(query.getStatus() != null, "tpl.c_status", ScriptConditionEnum.Eq, query.getStatus())
                .where(query.getParkId() != null, "tpl.c_park_id", ScriptConditionEnum.Eq, query.getParkId());

        return getDataPager(sqlQueryMate, pageSize, pageIndex, ParkingLot.class);
    }


}
